home *** CD-ROM | disk | FTP | other *** search
- /* IPCList code by Jim Luther, converted to C by Me <TR> */
- /* I've left a lot of the Pascal definitions, comments, and some code */
- /* in this (in comments) so you Pascal-heads can see it better */
-
- #include <Types.h>
- #include <memory.h>
- #include <Packages.h>
- #include <Errors.h>
- #include <quickdraw.h>
- #include <fonts.h>
- #include <dialogs.h>
- #include <windows.h>
- #include <menus.h>
- #include <events.h>
- #include <OSEvents.h>
- #include <Desk.h>
- #include <diskinit.h>
- #include <OSUtils.h>
- #include <resources.h>
- #include <toolutils.h>
- #include <AppleEvents.h>
- #include <EPPC.h>
- #include <GestaltEqu.h>
- #include <PPCToolbox.h>
- #include <Processes.h>
- #include <Balloons.h>
- #include <ALiases.h>
- #include <Processes.h>
- #include <StandardFile.h>
- #include <Folders.h>
- #include <AppleTalk.h>
-
-
- #define MaxTuples 100
- #define MaxPorts 100
- typedef unsigned char Tuple[104];
-
- /*
- TYPE
- Tuple = PACKED ARRAY[1..104] OF Char;
- { an AddrBlock (4 bytes), a one byte enumerator, and an EntityName (99 bytes) }
- */
-
- Tuple myRetBuff[100]; /* myRetBuff: ARRAY[1..MaxTuples] OF Tuple;{for NBP Lookup} */
- MPPParamBlock paramblk; /* paramblk: MPPParamBlock; */
- EntityName myEntityName; /* myEntityName: EntityName; */
- AddrBlock myAddrBlock; /* myAddrBlock: AddrBlock; */
- short i, j; /* i, j: integer; */
- short gCount; /* gCount: integer; */
- PortInfoRec gPortInfoBuffer[100]; /* gPortInfoBuffer: ARRAY[1..MaxPorts] OF PortInfoRec; */
- XPPParamBlock xppParamblk; /* xppParamblk: XPPParamBlock; */
- Str255 zoneName; /* zoneName: Str255; */
-
- OSErr gErr; /* gErr: OSErr; */
-
-
-
- #if 0
- /* Jim's orignal comment */
- {*********************************************************************}
- {*}
- {* IPCListPorts: Return a list of PortInfoRecs in the buffer pointed}
- {* to by thePortInfoBufferPtr. The actual number of}
- {* PortInfoRecs returned will be in theActualCount.}
- {* }
- {* myIPCListPorts}
- {* The function returns with any errors from IPCListPorts.}
- {* theStartIndex}
- {* The index into the port entry list. To start at the}
- {* beginning, use 0.}
- {* theRequestCount}
- {* The maximum number of portInfoRecs that can be returned. Make}
- {* sure the buffer pointed to by thePortInfoBufferPtr is at least}
- {* SizeOf(PortInfoRec) * theRequestCount.}
- {* theActualCount}
- {* This returns the actual number of PortInfoRecs returned in }
- {* the buffer pointed to by thePortInfoBufferPtr.}
- {* theObjStr}
- {* The NBP object to be used in the LocationNameRec.}
- {* theZoneStr}
- {* The NBP zone to be used in the LocationNameRec.}
- {* thePortInfoBufferPtr}
- {* This points to an array of PortInfoRecs. IPCListPorts fills it}
- {* with a list of ports matching thePPCPortRec at the location}
- {* specified by theLocationNameRec. The size of this array must}
- {* be at least SizeOf(PortInfoRec) * theRequestCount.}
- {* theIPCListPortsPBRec}
- {* The parameter block passed to the IPCListPorts call. The}
- {* startIndex, requestCount, portName, locationName, and bufferPtr}
- {* fields must be supplied. If the IPCListPorts call is made}
- {* asynchronously, the ioCompletion field must be supplied.}
- {* thePPCPortRec}
- {* IPCListPorts will only list ports that match the PPC port name}
- {* supplied. An equal sign (=) can be used for the name and/or}
- {* portTypeStr as a wildcard to match all ports names.}
- {* theLocationNameRec}
- {* IPCListPorts will list the ports at this location. The}
- {* NBP object and NBP zone must be chosen from the lists returned}
- {* by NBPLookup and GetZoneList. The NBP type can be application}
- {* specific. If you don't supply your own NBP type, you should}
- {* use "PPCToolBox" for the NBP type string. The}
- {* locationKindSelector field must be set to either ppcNoLocation}
- {* (which specifies the local computer) or ppcNBPLocation (which}
- {* specifies the complete NBP entity).}
- {*....................................................................}
-
- #endif
-
-
- OSErr myIPCListPorts(short theStartIndex, short theRequestCount, short *theActualCount, Str32 theObjStr, Str32 theZoneStr,
- PortInfoArrayPtr thePortInfoBufferPtr)
- {
-
- OSErr myErr;
- IPCListPortsPBRec theIPCListPortsPBRec;
- PPCPortRec thePPCPortRec;
- LocationNameRec theLocationNameRec;
- Str32 ppcWord = "\pPPCToolBox";
- /* List all PPC ports at the specified location */
- thePPCPortRec.nameScript = 0;
- thePPCPortRec.name[0] = 1;
- thePPCPortRec.name[1] = '='; /* match all names */
- thePPCPortRec.portKindSelector = ppcByString;
- thePPCPortRec.u.portTypeStr[0] = 1; /* match all names */
- thePPCPortRec.u.portTypeStr[1] = '='; /* match all names */
-
- theLocationNameRec.locationKindSelector = ppcNBPLocation; /* using an NBP construct */
- /* Move the passed infomation into the location name */
- BlockMove((Ptr)&theObjStr[0], (Ptr)&theLocationNameRec.u.nbpEntity.objStr, theObjStr[0] + 1);
- BlockMove((Ptr)&ppcWord[0], (Ptr)&theLocationNameRec.u.nbpEntity.typeStr, ppcWord[0] + 1);
- BlockMove((Ptr)&theZoneStr[0], (Ptr)&theLocationNameRec.u.nbpEntity.zoneStr, theZoneStr[0] + 1);
- /* last parameters */
- theIPCListPortsPBRec.startIndex = theStartIndex;
- theIPCListPortsPBRec.requestCount = theRequestCount;
- theIPCListPortsPBRec.portName = &thePPCPortRec;
- theIPCListPortsPBRec.locationName = &theLocationNameRec;
- theIPCListPortsPBRec.bufferPtr = thePortInfoBufferPtr;
-
- /* Call IPCListPorts synchronously */
- myErr = IPCListPortsSync(&theIPCListPortsPBRec);
-
- *theActualCount = theIPCListPortsPBRec.actualCount;
- return(myErr);
- }
-
- OSErr GetAllPPCAbleMachines(MPPParamBlock *paramblk)
- {
- /* This used to be the main section of the code. Now I call it to fill in */
- /* my list */
- xppParamblk.XCALL.csCode = xCall;
- xppParamblk.XCALL.xppSubCode = zipGetMyZone;
- xppParamblk.XCALL.xppTimeout = 3;
- xppParamblk.XCALL.xppRetry = 4;
- xppParamblk.XCALL.zipBuffPtr = &zoneName;
- xppParamblk.XCALL.zipInfoField[1] = 0;
- gErr = GetMyZone(&xppParamblk, false);
-
- if (gErr != noErr) {
- DebugStr("\pZone fail");
- zoneName[0] = 1;
- zoneName[1] = '*';
- }
- /* noZone is '*' */
-
-
- NBPSetEntity((Ptr)&myEntityName, "\p=", "\pPPCToolBox", zoneName);
-
- paramblk->NBP.interval = 5;
- paramblk->NBP.count = 5;
- paramblk->NBP.NBPPtrs.entityPtr = (Ptr)&myEntityName;
- paramblk->NBP.parm.Lookup.retBuffPtr = (Ptr)&myRetBuff;
- paramblk->NBP.parm.Lookup.retBuffSize = sizeof(myRetBuff);
- paramblk->NBP.parm.Lookup.maxToGet = MaxTuples;
- paramblk->NBP.parm.Lookup.numGotten = 0;
- gErr = PLookupName(paramblk, false);
-
- }
-
- OSErr GetPortsOnMachine(MPPParamBlock *paramblk)
- {
- if (paramblk->NBP.parm.Lookup.numGotten > 0) {
- for (i = 1; i < paramblk->NBP.parm.Lookup.numGotten; i++) {
- // {extract the NBP name}
- gErr = NBPExtract((Ptr)&myRetBuff, paramblk->NBP.parm.Lookup.numGotten, i, &myEntityName, &myAddrBlock);
-
- // writeln('Getting ports on ', myEntityName.objStr);
- // {get the list of PPC ports}
- gErr = myIPCListPorts(0, MaxPorts, &gCount, myEntityName.objStr, myEntityName.zoneStr, &gPortInfoBuffer);
-
- // FOR j = 1 TO gCount DO
- // Writeln(' ', gPortInfoBuffer[j].name.name);
-
- }
- }
- }
-